package com.cenxi.service;

import com.alibaba.fastjson.JSONObject;
import com.cenxi.util.EmailUtils;
import com.cenxi.util.RandomUtils;
import com.cenxi.util.SampleSmsSendService;
import com.cenxi.util.contents.Content;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * @Author cenxi
 * @Date 2023/9/6 16:14
 * @Version 1.0
 */
@Service
@Slf4j
public class SendService {

    @Autowired
    private EmailUtils emailUtils;

    @Autowired
    private SampleSmsSendService sampleSmsSendService;

    public Object email(String emailNum) {
        String title = "验证码测试";
        String html = "<h1>欢迎使用邮箱服务,你的验证码是: " + "<font style='color: red'>" + RandomUtils.getRandomNameStr(6) + "</font>" + ", 请妥善保管</h1>";
        emailUtils.sendHtml(title, html, emailNum);
        return "发送成功,请注意查收";
    }

    public Object sms(String smsNum) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", RandomUtils.getRandomName(6));
        String flag = sampleSmsSendService.sendSms(smsNum, jsonObject);
        if (Content.SMS_OK.equals(flag)) {
            return "发送短信成功,请注意接收";
        }
        return "短信发送失败";
    }
}
